% Info:
% 30-11-2014: changed to optimize performance
function DispSymMatrixMatlab(AA,NAME)

if ndims(AA) == 2
    N1 = size(AA,1);
    N2 = size(AA,2);
    N3 = 1;
    N4 = 1;
elseif ndims(AA) == 3
    N1 = size(AA,1);
    N2 = size(AA,2);
    N3 = size(AA,3); 
    N4 = 1;
elseif ndims(AA) == 4
    N1 = size(AA,1);
    N2 = size(AA,2);
    N3 = size(AA,3);
    N4 = size(AA,4);
end
disp(['% START DISPLAYING ' NAME])
if ndims(AA) == 2
    for g=1:N4
        for k=1:N3
            for j=1:N2
                if any(AA(:,j,k,g) ~= 0)
                    for i=1:N1
                        if AA(i,j,k,g) ~= 0
                            disp([NAME '(' num2str(i) ',' num2str(j) ')=' char(AA(i,j,k,g)) ';']);
                        end
                    end
                end
            end
        end
    end
end

if ndims(AA) == 3
    for g=1:N4
        for k=1:N3
            for j=1:N2
                if any(AA(:,j,k,g) ~= 0)
                    for i=1:N1
                        if AA(i,j,k,g) ~= 0
                            disp([NAME '(' num2str(i) ',' num2str(j) ',' num2str(k) ')=' char(AA(i,j,k,g)) ';']);
                        end
                    end
                end
            end
        end
    end
end

if ndims(AA) == 4   
    for g=1:N4
        for k=1:N3
            for j=1:N2
                if any(AA(:,j,k,g) ~= 0)
                    for i=1:N1
                        if AA(i,j,k,g) ~= 0
                            disp([NAME '(' num2str(i) ',' num2str(j) ',' num2str(k) ',' num2str(g) ')=' char(AA(i,j,k,g)) ';']);
                        end
                    end
                end
            end
        end
    end
end
disp(['% END DISPLAYING ' NAME])
end
